# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: donggu

import datetime
import functools
import logging

from absl import app

import experimental.prophet as prophet
from coin.exchange.bitmex.kr_rest.futures_product import BitmexFuturesProduct
from experimental import prophet as prophet
from experimental.prophet.ops import timeseries

start_time = datetime.datetime(2019, 8, 15)
end_time = start_time + datetime.timedelta(hours=2)


def model():
  ts = prophet.global_timestamp()

  order = prophet.coin_order_event('Futures',
                                   'Bitmex',
                                   start_time,
                                   end_time,
                                   'strategy-15.eu-west-1',
                                   'xunke33', ['order_price', 'order_qty'],
                                   ['order_submitted_time'])

  with prophet.control_if(order.new_row_indicator):
    # prophet.printer('%t %s %s', ts, order.order_price, order.order_qty)

    aggregator = prophet.scalar_value_aggregator([
        ts,
        order.order_price,
        order.order_qty,
    ])

  return aggregator


def main(argv):
  df = prophet.run_from_fastfeed_multiprocess(functools.partial(model),
                                              start_time,
                                              end_time,
                                              machine='feed-01.ap-northeast-1.aws',
                                              use_run_cache=False)

  print(df)


if __name__ == '__main__':
  logging.basicConfig(level='DEBUG')
  app.run(main)
